#include <QString>
#include <QJsonObject>
#include "poco/user.h"

namespace WordMemory
{
    User::User(int id,
         const QString &username,
         const QString &password,
         const QString &realName,
         const QString &createdAt)
        : _id(id)
        , _username(username)
        , _password(password)
        , _realName(realName)
        , _createdAt(createdAt)
    {}

    QJsonObject User::toJson() const
    {
        QJsonObject json;
        json["id"] = _id;
        json["username"] = _username;
        json["password"] = _password;
        json["real_name"] = _realName;
        json["created_at"] = _createdAt;
        return json;
    }

    User User::fromJson(const QJsonObject &json)
    {
        return User(
            json["id"].toInt(),
            json["username"].toString(),
            json["password"].toString(),
            json["real_name"].toString(),
            json["created_at"].toString());
    }
}
